home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / dcopy332.zip / DCUTIL.C < prev    next >
C/C++ Source or Header  |  1990-04-14  |  4KB  |  161 lines

  1. /*************************************************************
  2.  *                                                           *
  3.  * Program DCOPY - physical sector to sector copy              *
  4.  * Copyright (c) 1986 Joerg Genius, Munich, West-Germany     *
  5.  *                                                           *
  6.  *************************************************************/
  7.  
  8. #include <stdio.h>
  9. #include <alloc.h>
  10. #include <dos.h>
  11. #include "dcdefs.h"
  12.  
  13.  
  14. dcinit()
  15.  
  16. {
  17.    unsigned int cnt=120;
  18.    union REGS regs;
  19.  
  20.    while ((disk_buffer=malloc(cnt*512))==NULL)
  21.       cnt--;
  22.    if (cnt<=5) {
  23.       return -1;
  24.    }
  25.    blk_p_buffer=cnt;
  26.    regs.h.ah=0x19;
  27.    intdosx(®s,®s,NULL);
  28.    regs.h.dl=regs.h.al;
  29.    regs.h.ah=0x0e;
  30.    intdosx(®s,®s,NULL);
  31.    MAX_DRV=regs.h.al-1;
  32.    return 0;
  33. }
  34.  
  35.  
  36. get_drive_data(disk,drive_s)
  37.  
  38. int disk;
  39. struct drive_data *drive_s;
  40.  
  41. {
  42.    union REGS regs;
  43.  
  44.    regs.h.ah=0x1c;
  45.    regs.h.dl=disk+1;
  46.    intdosx(®s,®s,NULL);
  47.    if (regs.h.al==0xff) {
  48.       fprintf (stderr,text[7],disk+'A');
  49.       return 1;
  50.    }
  51.    drive_s->sec_p_cluster=regs.h.al;
  52.    drive_s->bytes_p_sec=regs.x.cx;
  53.    drive_s->cluster_p_drive=regs.x.dx;
  54.    drive_s->sec_p_drive=drive_s->sec_p_cluster*drive_s->cluster_p_drive;
  55.    switch (drive_s->sec_p_drive) {
  56.       case 768 :
  57.                  drive_s->sec_p_drive=800;
  58.                  break;
  59.       case 351 :
  60.                  drive_s->sec_p_drive=360;
  61.                  break;
  62.       case 708 :
  63.                  drive_s->sec_p_drive=720;
  64.                  break;
  65.       case 313 :
  66.                  drive_s->sec_p_drive=320;
  67.                  break;
  68.       case 630 :
  69.                  drive_s->sec_p_drive=640;
  70.                  break;
  71.       case 2371:
  72.                  drive_s->sec_p_drive=2400;
  73.                  break;
  74.       case 1426:
  75.                  drive_s->sec_p_drive=1440;
  76.                  break;
  77.       case 2847:
  78.                  drive_s->sec_p_drive=2880;
  79.                  break;
  80.       default:
  81.                  drive_s->sec_p_drive=0;
  82.    }
  83.    if (drive_s->sec_p_drive==0) {
  84.       fprintf (stderr,text[28],disk+'A');
  85.    } else
  86.       return 0;
  87. }
  88.  
  89.  
  90. unsigned int get_max_blocks(blocks_per_drive)
  91.  
  92. int blocks_per_drive;
  93.  
  94. {
  95.    switch (blocks_per_drive) {
  96.       case 2400 :
  97.                   disk_type=0;
  98.                   return (blk_p_buffer/30==0 ? blk_p_buffer-1 : (blk_p_buffer/30)*30);
  99.       case  800 :
  100.                   disk_type=1;
  101.                   return (blk_p_buffer/10==0 ? blk_p_buffer-1 : (blk_p_buffer/10)*10);
  102.       case  720 :
  103.                   disk_type=2;
  104.                   return (blk_p_buffer/18==0 ? blk_p_buffer-1 : (blk_p_buffer/18)*18);
  105.       case  640 :
  106.                   disk_type=3;
  107.                   return (blk_p_buffer/16==0 ? blk_p_buffer-1 : (blk_p_buffer/16)*16);
  108.       case  360 :
  109.                   disk_type=4;
  110.                   return (blk_p_buffer/9==0 ? blk_p_buffer-1 : (blk_p_buffer/9)*9);
  111.       case  320 :
  112.                   disk_type=5;
  113.                   return (blk_p_buffer/8==0 ? blk_p_buffer-1 : (blk_p_buffer/8)*8);
  114.       case 1440:
  115.                   disk_type=6;
  116.                   return (blk_p_buffer/9==0 ? blk_p_buffer-1 : (blk_p_buffer/9)*9);
  117.       case 2880:
  118.                   disk_type=7;
  119.                   return (blk_p_buffer/18==0 ? blk_p_buffer-1 : (blk_p_buffer/18)*18);
  120.    }
  121. }
  122.  
  123.  
  124. read_block(disk_src,start_block,num_blocks,buffer_adr)
  125.  
  126. int disk_src;
  127. unsigned int start_block,num_blocks;
  128. char *buffer_adr;
  129.  
  130. {
  131.    union REGS iregs;
  132.    struct SREGS isregs;
  133.    
  134.    iregs.h.al=disk_src;
  135.    iregs.x.dx=start_block;
  136.    iregs.x.cx=num_blocks;
  137.    iregs.x.bx=FP_OFF(buffer_adr);
  138.    isregs.ds=FP_SEG(buffer_adr);
  139.    int86x(0x25,&iregs,&iregs,&isregs);
  140.    return (iregs.h.al);
  141. }
  142.  
  143. write_block(disk_dest,start_block,num_blocks,buffer_adr)
  144.  
  145. int disk_dest;
  146. unsigned int start_block,num_blocks;
  147. char *buffer_adr;
  148.  
  149. {
  150.    union REGS iregs;
  151.    struct SREGS isregs;
  152.    
  153.    iregs.h.al=disk_dest;
  154.    iregs.x.dx=start_block;
  155.    iregs.x.cx=num_blocks;
  156.    iregs.x.bx=FP_OFF(buffer_adr);
  157.    isregs.ds=FP_SEG(buffer_adr);
  158.    int86x(0x26,&iregs,&iregs,&isregs);
  159.    return (iregs.h.al);
  160. }
  161.